/**
 * 
 */
package com.calf.module.loan.controller;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.calf.cn.controller.BaseController;
import com.calf.cn.entity.DataTables;
import com.calf.cn.service.BaseManager;
import com.calf.cn.utils.SearchUtil;
import com.calf.module.loan.entity.DitchName;

@Controller
@RequestMapping(value = "/ditchname")
public class DitchNameController implements BaseController<DitchName> {

	@Autowired
	private BaseManager baseManager;

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#home()
	 */
	@Override
	public String home() {
		return "calfloan/ditchname/ditchnamelist";
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#initTable(javax.servlet.http.
	 * HttpServletRequest)
	 */
	@Override
	public DataTables<DitchName> initTable(HttpServletRequest request) {
		Map<String, Object> parameters = SearchUtil.convertorEntitysToMap(request.getParameterMap());
		String name = (String) parameters.get("name");
		System.out.println(name);
		String sEcho = (String) parameters.get("sEcho");
		List<DitchName> ditchName = baseManager.query(DitchName.class, parameters);
		int total = baseManager.get("DitchName.queryCount", parameters);
		return new DataTables<DitchName>(sEcho, ditchName, ditchName.size(), total);
	}

	
	@Override
	public String addAndUpdateHome(Model model, String id) {
		if (StringUtils.isNotBlank(id)) {
			model.addAttribute("entity", baseManager.get("DitchName.getIcePersonById", new Object[] { id }));
		}
		return "calfloan/iceperson/addIcePerson";
	}


	/*
	 * 
	 * (non-Javadoc)
	 * 
	 * @see com.calf.cn.controller.BaseController#saveAdd(java.lang.Object)
	 */
	@Override
	public int saveAdd(DitchName entity) {
		Subject currentUser = SecurityUtils.getSubject();
		return baseManager.insert(entity);
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#delete(java.lang.Long)
	 */
	@Override
	public int delete(Long id) {
		return baseManager.delete(DitchName.class, new Object[] { id });
	}

	@Override
	public int delete(String id) {
		return baseManager.delete(DitchName.class, new Object[] { id });
	}

	/*
	 * (非 Javadoc) Description:
	 * 
	 * @see com.calf.cn.controller.BaseController#saveUpdate(java.lang.Object)
	 */
	@Override
	public int saveUpdate(DitchName entity) {
		Subject currentUser = SecurityUtils.getSubject();
		return baseManager.update(entity);
	}

}
